package com.solidtrust.util;

import org.apache.commons.lang3.StringUtils;

public class ScrapeUtil {

	/*
	 * 发 动 机 ：1.6T 184马力 L4
	 * 变 速 器 ：6挡手自一体车辆级别：小型车 
	 * 颜　　色：绿色燃油标号：97号(京95号)
	 * 驱动方式：前置前驱
	 */
	public static String getString(String s, String key){
		String value = null;
		if(s.startsWith(key)){
			int p = s.indexOf(":");
			if(p == -1){
				p = s.indexOf("：");
			}
			value = s.substring(p + 1).trim();
			int i = value.indexOf("(");
			if(i == -1){
				i = value.indexOf("（");
			}
			if(i != -1){
				value = value.substring(0, i);
			}
		}
		return value;
	}
	
	public static String deleteBracket(String value){
		int i = value.indexOf("(");
		if(i == -1){
			i = value.indexOf("（");
		}
		if(i != -1){
			value = value.substring(0, i);
		}
		return value;
	}
	
	public static String getBuild(String title){
		try {
			//build
			int x = title.indexOf("款");
			String build = title.substring(x - 4, x);
			if(!StringUtils.isNumeric(build)){
				if(build.startsWith("0") || build.startsWith("1")){
					return "20" + build.substring(2);
				}
				return "19" + build.substring(2);
			}
			return build;
		} catch (Exception e) {
			return null;
		}
	}
	
	
	public static int getWan(String price){
		return (int)(Double.parseDouble(price) * 10000);
	}
	
}
